package com.zhida.userservice.controller;

import com.fasterxml.jackson.core.JsonProcessingException;


import com.zhida.common.dto.UserDTO;
import com.zhida.common.entity.Result;
import com.zhida.userservice.entity.User;
import com.zhida.userservice.service.IUserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Your Name
 * @since 2024-07-15
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    IUserService userService;

    @PostMapping("/passwordLogin")
    public Result<?> passwordLogin(@RequestBody UserDTO userDTO){
        return userService.passwordLogin(userDTO);
    }
    @PostMapping("/codeLogin")
    public Result<?> codeLogin(@RequestBody UserDTO userDTO){
        return userService.codeLogin(userDTO);
    }

    @PostMapping("/register")
    public Result<?> register(@RequestBody UserDTO userDTO){
        return userService.register(userDTO);
    }

    @PostMapping("/updateUserInfo")
    public Result<?> updateUserInfo(@RequestBody User user){
        return userService.updateUserInfo(user);
    }

    @PostMapping("/getUserInfo")
    public Result<?> getUserInfo() throws JsonProcessingException {
        return userService.getUserInfo();
    }

    @GetMapping("/sendCode/{username}")
    public Result<?> sendCode(@PathVariable String username){
        return userService.sendCode(username);
    }
}
